layui.define(["table", "element"], function (exports) {
  var $ = layui.$,
    table = layui.table,
    element = layui.element;
  var agenda =
    layui.sessionData("technicalCategory").key == undefined
      ? "0"
      : layui.sessionData("technicalCategory").key;
  var status =
    layui.sessionData("status").key == undefined
      ? "3"
      : layui.sessionData("status").key;
  // 已办待办根据本地存储默认选中
  element.tabChange("technicalRevieAgenda", agenda);
  //技审类型根据本地存储默认选中
  element.tabChange(`technicalRevieTab${agenda}`, status);
  initPageTechnical(agenda, status);
  // agenda=0待办    agenda=1已办
  if (agenda == "0") {
    switch (status) {
      case "1":
        element.tabChange(`technicalRevieTab${agenda}`, "1");
        position = `#guardianshipProgram${agenda}${status}`;
        toolbarOperatee = "#guardianshipOpera";
        OperateeWidth = 350;
        hidecolumn = false;

        break;
      case "2":
        element.tabChange(`technicalRevieTab${agenda}`, "2");
        position = `#technicalReConsultation${agenda}${status}`;
        toolbarOperatee = "#technicalReConsultationOprea";
        OperateeWidth = 525;
        hidecolumn = false;
        break;
      case "3":
        element.tabChange(`technicalRevieTab${agenda}`, "3");
        position = `#technicalReview${agenda}${status}`;
        toolbarOperatee = "#technicalReviewOprea";
        OperateeWidth = 525;
        hidecolumn = false;
        break;
      case "4":
        element.tabChange(`technicalRevieTab${agenda}`, "4");
        position = `#protectionScheme${agenda}${status}`;
        toolbarOperatee = "#protectionSchemeOprea";
        OperateeWidth = 260;
        hidecolumn = false;
        break;
      case "5":
        element.tabChange(`technicalRevieTab${agenda}`, "5");
        position = `#combinedTransformation${agenda}${status}`;
        toolbarOperatee = "#combinedTransformationOpra";
        OperateeWidth = 320;
        hidecolumn = false;
        break;
    }
  } else {
    switch (status) {
      case "1":
        element.tabChange(`technicalRevieTab${agenda}`, "1");
        position = `#guardianshipProgram${agenda}${status}`;
        toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
        OperateeWidth = 350;
        hidecolumn = true;

        break;
      case "2":
        element.tabChange(`technicalRevieTab${agenda}`, "2");
        position = `#technicalReConsultation${agenda}${status}`;
        toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
        OperateeWidth = 525;
        hidecolumn = false;
        break;
      case "3":
        element.tabChange(`technicalRevieTab${agenda}`, "3");
        position = `#technicalReview${agenda}${status}`;
        toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
        OperateeWidth = 525;
        hidecolumn = true;
        break;
      case "4":
        element.tabChange(`technicalRevieTab${agenda}`, "4");
        position = `#protectionScheme${agenda}${status}`;
        toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
        OperateeWidth = 260;
        hidecolumn = true;
        break;
      case "5":
        element.tabChange(`technicalRevieTab${agenda}`, "5");
        position = `#combinedTransformation${agenda}${status}`;
        toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
        OperateeWidth = 320;
        hidecolumn = true;
        break;
    }
  }
  // 已办待办切换
  element.on("tab(technicalRevieAgenda)", function (data) {
    layui.sessionData("technicalCategory", {
      key: "key",
      value: $(this).attr("lay-id"),
    });
    var agenda = layui.sessionData("technicalCategory").key;
    initPageTechnical(agenda, status);
  });
  function initPageTechnical(agenda, status) {
    if (agenda == "0") {
      switch (status) {
        case "1":
          element.tabChange(`technicalRevieTab${agenda}`, "1");
          position = `#guardianshipProgram${agenda}${status}`;
          toolbarOperatee = `#guardianshipOpera${agenda}${status}`;
          OperateeWidth = 350;
          hidecolumn = false;

          break;
        case "2":
          element.tabChange(`technicalRevieTab${agenda}`, "2");
          position = `#technicalReConsultation${agenda}${status}`;
          toolbarOperatee = `#technicalReConsultationOprea${agenda}${status}`;
          OperateeWidth = 525;
          hidecolumn = false;
          break;
        case "3":
          element.tabChange(`technicalRevieTab${agenda}`, "3");
          position = `#technicalReview${agenda}${status}`;
          toolbarOperatee = `#technicalReviewOprea${agenda}${status}`;
          OperateeWidth = 525;
          hidecolumn = false;
          break;
        case "4":
          element.tabChange(`technicalRevieTab${agenda}`, "4");
          position = `#protectionScheme${agenda}${status}`;
          toolbarOperatee = `#protectionSchemeOprea${agenda}${status}`;
          OperateeWidth = 260;
          hidecolumn = false;
          break;
        case "5":
          element.tabChange(`technicalRevieTab${agenda}`, "5");
          position = `#combinedTransformation${agenda}${status}`;
          toolbarOperatee = `#combinedTransformationOpra${agenda}${status}`;
          OperateeWidth = 320;
          hidecolumn = false;
          break;
      }
    } else {
      OperateeWidth = 200;
      hidecolumn = true;
      switch (status) {
        case "1":
          element.tabChange(`technicalRevieTab${agenda}`, "1");
          position = `#guardianshipProgram${agenda}${status}`;
          toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
          break;
        case "2":
          element.tabChange(`technicalRevieTab${agenda}`, "2");
          position = `#technicalReConsultation${agenda}${status}`;
          toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
          break;
        case "3":
          element.tabChange(`technicalRevieTab${agenda}`, "3");
          position = `#technicalReview${agenda}${status}`;
          toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
          break;
        case "4":
          element.tabChange(`technicalRevieTab${agenda}`, "4");
          position = `#protectionScheme${agenda}${status}`;
          toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
          break;
        case "5":
          element.tabChange(`technicalRevieTab${agenda}`, "5");
          position = `#combinedTransformation${agenda}${status}`;
          toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
          break;
      }
    }
    getList(position, status, toolbarOperatee, OperateeWidth, hidecolumn);
    commissionStatistics(agenda);
    //数量渲染
    function commissionStatistics(agenda) {
      $.ajax({
        type: "POST",
        async: false, //异步执行
        url: base_url + "/technicalAuditOpinion/commissionStatistics",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        contentType: "application/json",
        data: JSON.stringify({ category: agenda }),
        success: function (data) {
          if (data.code == 200) {
            var data = data.data;
            $("#reviewBacklogSum").html(data.reviewBacklogSum);
            $("#reviewDonelogSum").html(data.haveDoneSum);
            $(".reviewLicensing").html(data.reviewLicensing);
            $(".protectionPlan").html(data.protectionPlan);
            //监护大纲
            $(".TheOutlineCount").html(data.TheOutlineCount);
            //征询类
            $(".reviewConsult").html(data.reviewConsult);
          }
        },
      });
    }
    // 技审类型切换
    element.on("tab(technicalRevieTab" + agenda + ")", function (data) {
      layui.sessionData("status", {
        key: "key",
        value: $(this).attr("data-status"),
      });
      var status = layui.sessionData("status").key;
      if (agenda == "0") {
        switch (status) {
          case "1":
            position = `#guardianshipProgram${agenda}${status}`;
            toolbarOperatee = `#guardianshipOpera${agenda}${status}`;
            OperateeWidth = 350;
            hidecolumn = false;
            break;
          case "2":
            position = `#technicalReConsultation${agenda}${status}`;
            toolbarOperatee = `#technicalReConsultationOprea${agenda}${status}`;
            OperateeWidth = 525;
            hidecolumn = false;
            break;
          case "3":
            position = `#technicalReview${agenda}${status}`;
            toolbarOperatee = `#technicalReviewOprea${agenda}${status}`;
            OperateeWidth = 525;
            hidecolumn = false;
            break;
          case "4":
            position = `#protectionScheme${agenda}${status}`;
            toolbarOperatee = `#protectionSchemeOprea${agenda}${status}`;
            OperateeWidth = 260;
            hidecolumn = false;
            break;
          case "5":
            position = `#combinedTransformation${agenda}${status}`;
            toolbarOperatee = `#combinedTransformationOpra${agenda}${status}`;
            OperateeWidth = 320;
            hidecolumn = false;
            break;
        }
      } else if (agenda == "1") {
        OperateeWidth = 200;
        hidecolumn = true;
        switch (status) {
          case "1":
            position = `#guardianshipProgram${agenda}${status}`;
            toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
            break;
          case "2":
            position = `#technicalReConsultation${agenda}${status}`;
            toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
            break;
          case "3":
            position = `#technicalReview${agenda}${status}`;
            toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
            break;
          case "4":
            position = `#protectionScheme${agenda}${status}`;
            toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
            break;
          case "5":
            position = `#combinedTransformation${agenda}${status}`;
            toolbarOperatee = `#selectTypeOpea${agenda}${status}`;
            break;
        }
      }
      getList(position, status, toolbarOperatee, OperateeWidth, hidecolumn);
    });
    function getList(
      position,
      status,
      toolbarOperatee,
      OperateeWidth,
      hidecolumn
    ) {
      table.render({
        elem: position,
        skin: "nob", // 无边框风格
        height: "full-220",
        url: base_url + "/report/selectIssueProjectList", //模拟接口
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        parseData: function (res) {
          return {
            code: 0,
            count: res.data.projectList.total,
            data: res.data.projectList.list,
            msg: res.data.message,
          };
        },
        cols: [
          [
            { field: "no", title: "编号", align: "center", width: 130 },
            {
              field: "projectName",
              title: "工程名称",
              align: "center",
              width: 400,
              event: "projectName",
              templet: function (item) {
                return (
                  "<div title=" +
                  item.projectName +
                  " class='whiteSpace'>" +
                  item.projectName +
                  "</div>"
                );
              },
            },
            {
              field: "flowStatus",
              title: "状态",
              align: "center",
              templet: function (item) {
                return (
                  "<div title=" +
                  item.flowStatus +
                  " class='whiteSpace'>" +
                  item.flowStatus +
                  "</div>"
                );
              },
            },
            {
              field: "reviewStatus",
              title: "待办描述",
              align: "center",
              width: 260,
              hide: hidecolumn,
            },
            {
              field: "insertDate",
              title: "创建时间",
              width: 210,
              align: "center",
            },
            {
              field: "updateTime",
              title: "处理时间",
              width: 210,
              align: "center",
              hide: !hidecolumn,
            },
            {
              title: "操作",
              width: OperateeWidth,
              align: "center",
              // fixed: "right",
              toolbar: toolbarOperatee,
            },
          ],
        ],
        page: true,
        limit: 5,
        limits: [5, 10, 15, 20, 25, 30],
        text: { none: "无数据" },
        where: { selectType: status, agenda },
        done: function (res, curr, count) {
          // 表格渲染完成之后的回调
          var that = this.elem.next();
          res.data.forEach(function (item, index) {
            //console.log(item.empName);item表示每列显示的数据
            if (index % 2 == 0) {
              var tr = that
                .find(".layui-table-box tbody tr[data-index='" + index + "']")
                .css("background-color", "transparent");
            } else {
              var tr = that
                .find(".layui-table-box tbody tr[data-index='" + index + "']")
                .css("background", "#EDF2FB");
            }
          });
        },
      });
    }
  }
  exports("contlist", {});
});
